import 'package:flutter/material.dart';
import 'package:klcpopup/klcpopup.dart';

import '../widgets/clear_messages_popup.dart';
import '../widgets/login_popup.dart';
import '../widgets/report_popup.dart';
import '../widgets/join_team_popup.dart';
import '../widgets/delete_account_popup.dart';
import 'toast_helper.dart';

class PopupHelper {
  static void showPopup(
    BuildContext context, {
    required Widget child,
    KLCPopupHorizontalLayout horizontalLayout = KLCPopupHorizontalLayout.center,
    KLCPopupVerticalLayout verticalLayout = KLCPopupVerticalLayout.center,
    KLCPopupShowType showType = KLCPopupShowType.fadeIn,
    KLCPopupDismissType dismissType = KLCPopupDismissType.fadeOut,
    VoidCallback? onDismiss,
  }) {
    final popupController = KLCPopupController();

    showKLCPopup(
      context,
      controller: popupController,
      horizontalLayout: horizontalLayout,
      verticalLayout: verticalLayout,
      showType: showType,
      dismissType: dismissType,
      child: Material(color: Colors.transparent, child: child),
    );
  }

  static void showLoginDialog(
    BuildContext context, {
    VoidCallback? onLoginPressed,
    VoidCallback? onCancelPressed,
  }) {
    final popupController = KLCPopupController();

    showKLCPopup(
      context,
      controller: popupController,
      horizontalLayout: KLCPopupHorizontalLayout.center,
      verticalLayout: KLCPopupVerticalLayout.center,
      showType: KLCPopupShowType.bounceInFromLeft,
      dismissType: KLCPopupDismissType.bounceOutToBottom,
      child: Material(
        color: Colors.transparent,
        child: LoginPromptDialog(
          onLoginPressed: () {
            popupController.dismiss();
            onLoginPressed?.call();
          },
          onCancelPressed: () {
            popupController.dismiss();
            onCancelPressed?.call();
          },
        ),
      ),
    );
  }

  static void showReportDialog(
    BuildContext context, {
    Function(ReportType reportType)? onReportSubmitted,
    VoidCallback? onCancelPressed,
  }) {
    final popupController = KLCPopupController();

    showKLCPopup(
      context,
      controller: popupController,
      horizontalLayout: KLCPopupHorizontalLayout.center,
      verticalLayout: KLCPopupVerticalLayout.center,
      showType: KLCPopupShowType.bounceInFromRight,
      dismissType: KLCPopupDismissType.bounceOutToBottom,
      child: Material(
        color: Colors.transparent,
        child: ReportPopupDialog(
          onReportSubmitted: (reportType) {
            popupController.dismiss();
            onReportSubmitted?.call(reportType);
            ToastHelper.success(
              'Report submitted successfully',
              context: context,
            );
          },
          onCancelPressed: () {
            popupController.dismiss();
            onCancelPressed?.call();
            ToastHelper.info('Report cancelled', context: context);
          },
        ),
      ),
    );
  }

  static void showJoinTeamDialog(
    BuildContext context, {
    VoidCallback? onJoinPressed,
    VoidCallback? onCancelPressed,
  }) {
    final popupController = KLCPopupController();

    showKLCPopup(
      context,
      controller: popupController,
      horizontalLayout: KLCPopupHorizontalLayout.center,
      verticalLayout: KLCPopupVerticalLayout.center,
      showType: KLCPopupShowType.bounceInFromTop,
      dismissType: KLCPopupDismissType.bounceOutToBottom,
      child: Material(
        color: Colors.transparent,
        child: JoinTeamDialog(
          onJoinPressed: () {
            popupController.dismiss();
            onJoinPressed?.call();
          },
          onCancelPressed: () {
            popupController.dismiss();
            onCancelPressed?.call();
          },
        ),
      ),
    );
  }

  static void showClearMessagesDialog(
    BuildContext context, {
    VoidCallback? onConfirmPressed,
    VoidCallback? onCancelPressed,
  }) {
    final popupController = KLCPopupController();

    showKLCPopup(
      context,
      controller: popupController,
      horizontalLayout: KLCPopupHorizontalLayout.center,
      verticalLayout: KLCPopupVerticalLayout.center,
      showType: KLCPopupShowType.bounceInFromTop,
      dismissType: KLCPopupDismissType.bounceOutToBottom,
      child: Material(
        color: Colors.transparent,
        child: ClearMessagesDialog(
          onConfirmPressed: () {
            popupController.dismiss();
            onConfirmPressed?.call();
          },
          onCancelPressed: () {
            popupController.dismiss();
            onCancelPressed?.call();
          },
        ),
      ),
    );
  }

  static void showDeleteAccountDialog(
    BuildContext context, {
    VoidCallback? onDeletePressed,
    VoidCallback? onCancelPressed,
  }) {
    final popupController = KLCPopupController();

    showKLCPopup(
      context,
      controller: popupController,
      horizontalLayout: KLCPopupHorizontalLayout.center,
      verticalLayout: KLCPopupVerticalLayout.center,
      showType: KLCPopupShowType.bounceInFromTop,
      dismissType: KLCPopupDismissType.bounceOutToBottom,
      child: Material(
        color: Colors.transparent,
        child: DeleteAccountDialog(
          onDeletePressed: () {
            popupController.dismiss();
            onDeletePressed?.call();
          },
          onCancelPressed: () {
            popupController.dismiss();
            onCancelPressed?.call();
          },
        ),
      ),
    );
  }

  static void showCustomDialog(
    BuildContext context, {
    required Widget child,
    KLCPopupShowType showType = KLCPopupShowType.slideInFromBottom,
    KLCPopupDismissType dismissType = KLCPopupDismissType.slideOutToBottom,
    VoidCallback? onDismiss,
  }) {
    final popupController = KLCPopupController();

    showKLCPopup(
      context,
      controller: popupController,
      horizontalLayout: KLCPopupHorizontalLayout.center,
      verticalLayout: KLCPopupVerticalLayout.center,
      showType: showType,
      dismissType: dismissType,
      child: Material(color: Colors.transparent, child: child),
    );
  }
}
